/**
 * 
 * @authors Fengyu
 * @date    2017-07-11 17:00:29
 * @version $Id$
 */

//querySelectorAll
function queryAll(){
	if (typeof arguments[0] === 'string') {
		return document.querySelectorAll(arguments[0])
	} else {
		throw new Error('这是querySelectorAll方法，你TM能不能按套路出牌？')
	}
}
//querySelector
function query(){
	if (typeof arguments[0] === 'string') {
		return document.querySelector(arguments[0])
	} else {
		throw new Error('这是querySelector方法，你TM能不能按套路出牌？')
	}
}
 //通过name获取
function byName(){
	if (arguments.length !== 0){
		if (typeof arguments[0] === 'string') {
			return document.getElementsByName(arguments[0])
		}else{
			throw new Error('参数必须为字符串');
		}
	}else{
		throw new Error('参数不能为Null')
	}
};
//通过标签名获取
function byTag(){
	var arglen = arguments.length;
	if (arglen!==0) {
		if (arglen === 1) {
			if (typeof arguments[0]==='string') {
				return document.getElementsByTagName(arguments[0]);
			} else {
				throw new Error('参数必须为字符串');
			}
		} else if(typeof arguments[0]==='object') {
			return arguments[0].getElementsByTagName(arguments[1])
		}else{
			throw new Error('请检查参数的第一个是有效节点');
		}
	} else {
		throw new Error('参数不能为Null')
	}
};
//通过classname
function byClass(){
	var arglen = arguments.length;
	if (arglen!==0) {
		if (arglen === 1) {
			if (typeof arguments[0]==='string') {
				return document.getElementsByClassName(arguments[0]);
			} else {
				throw new Error('参数必须为字符串');
			}
		} else if(typeof arguments[0]==='object') {
			return arguments[0].getElementsByClassName(arguments[1])
		}else{
			throw new Error('请检查参数的第一个是有效节点');
		}
	} else {
		throw new Error('参数不能为Null')
	}
};
//通过ID获取
function byId(){
	if (arguments.length !== 0){
		if (typeof arguments[0] === 'string') {
			return document.getElementById(arguments[0])
		}else{
			throw new Error('参数必须为字符串');
		}
	}else{
		throw new Error('参数不能为Null')
	}
};
//获取元素样式
function gStyle( obj,attr){
	return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj)[attr];
};















//轮播封装
function loop(wrap,time){
	var iBox = byClass(wrap,'i-box')[0],
		tBox = byClass(wrap,'t-box')[0],
		list = byTag(tBox,'li'),
		img = byTag(iBox,'li'),
		btn = byClass(wrap,'btn'),
		len = img.length,
		index = 0,
		timer,
		listName;
		fengyu();

	function fengyu(){
		listName = list[index].className;
		auto();
		for (var i = 0; i < len; i++) {
			list[i].i = i;
			list[i].onclick = function(){
				for (var i = 0; i < len; i++) {
					list[i].className = '';
					img[i].style.display = 'none';
				}
				index = this.i;
				list[index].className = listName;
				img[index].style.display = 'block';
			}
		};
		for (var j = 0; j < btn.length; j++) {
			btn[j].j = j;
			btn[j].onclick = function(){
				for (var i = 0; i < len; i++) {
					list[i].className = '';
					img[i].style.display = 'none';
				}
				if (this.j) {
					index++;
					index %= len;
					list[index].className = listName;
					img[index].style.display = 'block';
				} else {
					index--;
					if(index<0)index=len-1;
					list[index].className = listName;
					img[index].style.display = 'block';
				}
			}
		}
		
		

		//定时器
		function auto(){

			timer = setInterval(function(){
				for (var i = 0; i < len; i++) {
					list[i].className = '';
					img[i].style.display = 'none';
				}
				index++;
				index %= len;
				list[index].className = listName;
				img[index].style.display = 'block';

			},time);
		}
			
		wrap.onmouseenter = function(){
			clearInterval(timer);
		}
		wrap.onmouseleave = auto;
	}
	
}
